<script setup lang="ts">
import { PropType } from 'vue'
import { ActionOptioins, ListItem, ListOptions } from './types'
import { toLine } from '../../../utils'

let props = defineProps({
  // 列表的内容
  list: {
    type: Array as PropType<ListOptions[]>,
    required: true
  },
  // 操作内容
  actions: {
    type: Array as PropType<ActionOptioins[]>,
    default: () => []
  }
})
let emits = defineEmits(['clickItem', 'clickAction'])

let clickItem = (item: ListItem, index: number) => {
  emits('clickItem', item, index)
}

let clickAction = (action: ActionOptioins, i: number) => {
  emits('clickItem', action, i)
}
</script>

<template>
  <el-tabs class="list-tabs__item">
    <el-tab-pane
      v-for="(item, index) in props.list"
      :key="index"
      :label="item.title"
    >
      <el-scrollbar max-height="400">
        <div
          class="container"
          v-for="(item1, index1) in item.content"
          :key="index1"
          @click="clickItem(item1, index1)"
        >
          <div class="avatar" v-if="item1.avatar">
            <el-avatar size="small" :src="item1.avatar" />
          </div>
          <div class="content">
            <div v-if="item1.title" class="title">
              <div>{{ item1.title }}</div>
              <el-tag :type="item1.tagType" size="small" v-if="item1.tag">{{
                item1.tag
              }}</el-tag>
            </div>
            <div v-if="item1.desc">{{ item1.desc }}</div>
            <div class="time" v-if="item1.time">{{ item1.time }}</div>
          </div>
        </div>
        <div class="actions">
          <div
            class="aciton-item"
            :class="{ border: i != actions.length }"
            v-for="(action, i) in actions"
            :key="i"
            @click="clickAction(action, i)"
          >
            <div class="action-icon" v-if="action.icon">
              <component :is="`el-icon-${toLine(action.icon)}`"></component>
            </div>
            <div class="action-text">{{ action.text }}</div>
          </div>
        </div>
      </el-scrollbar>
    </el-tab-pane>
  </el-tabs>
</template>

<style lang="scss" scoped>
.container {
  display: flex;
  align-items: center;
  padding: 12px 20px;
  cursor: pointer;
  &:hover {
    background: #e6f6ff;
  }

  .avatar {
    margin-left: 20px;
    flex: 1;
  }

  .content {
    flex: 5;
    .title {
      display: flex;
      align-items: center;
      justify-content: space-between;
    }
    .time {
      font-size: 12px;
      color: #999;
      margin-top: 4px;
    }
  }
}

.actions {
  height: 30px;
  display: flex;
  align-items: center;
  border-top: 1px solid #eee;
  padding-top: 10px;
  .aciton-item {
    height: 30px;
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    &:hover {
      background: #e6f6ff;
    }
  }
  .action-icon {
    margin-right: 4px;
    position: relative;
    top: 2px;
  }
}

.border {
  border-right: 1px solid #eee;
}
</style>
